Skip to content

BUG: If both index and axis are passed to DataFrame.drop, raise a clear error #61855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 18, 2025

Conversation

khemkaran10
Copy link
Contributor

@khemkaran10 khemkaran10 commented Jul 14, 2025

@khemkaran10
Copy link
Contributor Author

pre-commit.ci autofix

@khemkaran10 khemkaran10 changed the title Both index and axis are passed to drop() it will raise a better error FIX BUG: If both index and axis are passed to drop(), it will raise ValueError with clear message. Jul 14, 2025
@khemkaran10
Copy link
Contributor Author

@camriddell I have made the changes.

@camriddell
Copy link

camriddell commented Jul 15, 2025

Can @rhshadrach take a look and provide some guidance? If we want to maintain backwards compat. then this is likely the final form of this PR.

However there is a deeper issue that is not present in either (thanks for finding these @khemkaran10) DataFrame.reindex, DataFrame.rename. Namely, those methods have a default of axis=None and can therefore check when that value is passed, whereas in .drop the axis argument defaults to axis=0 thus making it always "set". So we can check for axis==1 as @khemkaran10 did in the PR (or axis != 0).

@jbrockmendel
Copy link
Member

LGTM cc @rhshadrach

@rhshadrach rhshadrach changed the title FIX BUG: If both index and axis are passed to drop(), it will raise ValueError with clear message. BUG: If both index and axis are passed to DataFrame.drop, raise a clear error Jul 18, 2025
@rhshadrach rhshadrach added Bug Error Reporting Incorrect or improved errors from pandas labels Jul 18, 2025
@rhshadrach rhshadrach merged commit 6a6a1ba into pandas-dev:main Jul 18, 2025
51 checks passed
@rhshadrach
Copy link
Member

Thanks @khemkaran10!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: drop doesn't recognise MultiIndexes
4 participants